function ContactSelect_Code() {
	var buffer = new StringBuffer();
	buffer.append('<div id="find2" class="finds2" style="z-index:100;"><div class="searchinput ui-border-radius"><input id="keyword2" class="bordersolid" type="text" value="" onblur="Show_Search2()" onkeyup="ContactSelect_Search();"/><div id="searchicon2" class="searchicon"><img src="img/jing.jpg"/></div><div id="searchicons2" class="searchicons"><img src="img/jings.jpg"/></div></div></div>');
	buffer.append('<div class="horizen border-bottom" style="z-index:100;">></div>');
	return buffer.toString();
};

function Init_ContactSelect_Code()
{
	get("find").addEventListener("tap",function(){
		$("#searchicon").hide();
	    $("#searchicons").show();
	    $("#keyword").attr("placeholder","联系人姓名、手机");
		if($("keyword").val()!="")
		{
			//WorkMate_Search();
		}
	});
	get("screen").addEventListener("tap",function(){
		OpenScreen(Contact_Search_Code(),function(){
			Init_Contact_Search();
		},Contact_Search);
		stopEvent();
	});
};

function Init_ContactSelect_Search(){
	mui(".option").on("tap",".date",function(){
		obj=this;
			var t=new Date();
			if($(this).val()!="")
			{
				var year_month_day=$(this).val().split("-");
				t.setFullYear(year_month_day[0]);
				t.setMonth(year_month_day[1]-1);
				t.setDate(year_month_day[2]);
			}
			plus.nativeUI.pickDate( function(e){
				var d=e.date;
				$(obj).val((d.getFullYear()+"-"+(d.getMonth()+1)+"-"+d.getDate()).ToDate());
			},function(e){
				console.log( "未选择日期："+e.message );
			},{date:t});
	});
	
};

function Contact_SearchSelect_Code()
{
	var buffer = new StringBuffer();
	buffer.append('<div class="searchline" style="margin-top:10px;"><div class="names">关联状态</div><div class="option"><select id="state_search"><option value="">全部</option><option value="yes">已关联客户</option><option value="no">未关联客户</option></select></div></div>');
	buffer.append('<div class="searchline"><div class="names">创建时间</div><div class="option"><input id="begindate_search" type="text" class="date" placeholder="开始时间" readonly="readonly"/><input id="enddate_search" type="text" class="date" placeholder="结束时间" readonly="readonly"/></div></div>');
	return buffer.toString();
};

function ContactSelect_Data(data) {
	var buffer = new StringBuffer();
	$(data).each(function(i,info){
		var mobile=info.Mobile;
		if(mobile.Trim()==""){mobile=info.Phone;}
		if(mobile.Trim()==""){mobile="暂无电话";}
		buffer.append('<div class="customerlist border-bottom" id="'+info.ID+'"><div class="customername">'+info.Name+'</div><div class="customerinfo"><div class="state">'+mobile+'</div><div class="lastconntime">'+info.CreateDate.ToTime()+'</div></div></div>');
	});
	return buffer.toString();
};

function Receive_ContactSelect(pageindex)
{
	var data = {};
			data.act = "Find_Contact";
			data.userid=userid;
			data.comid=comid;
			data.pageindex=pageindex;
			data.source=source;
			data.pagesize=PAGE_SIZE20;
			data.keyword = $("#keyword2").val();
		    data.timer = RUndefined($("#begindate_search").val()) + "～" + RUndefined($("#enddate_search").val());
		    data.state = "no";
		    data.type = 1;
		    data.lowers = "";
		    data.sign=GetSign(data.act);
			mui.getJSON(crm_domain, data, function(json) {
				if(json.data.list.length>0)
				{
					if(pageindex==1)
					{
						$("#contentlist4").html(ContactSelect_Data(json.data.list));
					}else{
						$("#contentlist4").append(ContactSelect_Data(json.data.list));
					}
					setTimeout(function(){
						Init_ContactSelect();
						myScroll3.refresh();
					},500); //需要延迟500毫秒加载，否则当数量少时不能下拉
					if(json.data.list.length!=data.pagesize)
					{
						$("#loading4").html("");
					}else{
						$("#loading4").html('<img src="img/loading.gif"/>');
					}
				}else
				{
					
					if(pageindex==1)
					{
						$("#contentlist4").html("");
						$("#loading4").html("主人，没有找到您需要的数据"); 
					}
					else
					{
						$("#loading4").html("没有更多了");
					}
				}
				
         		pageindex = parseInt($("#divmsg4").attr("pageindex"))+1;
         		$("#divmsg4").attr("pageindex",pageindex);
			});
};

function ContactSelect_Search(){
	pageindex=1;
	$("#divmsg4").attr("pageindex","0");
	Receive_ContactSelect(1);
};

function Init_ContactSelect()
{
	mui("#contentlist4").off("tap",".customerlist");
	mui("#contentlist4").on("tap",".customerlist",function(){
		var data = {};
		data.userid=userid;
		data.comid=comid;
		data.source=source;
        data.act = "Conn_Contact";
        data.id=$(this).attr("id");
        data.customerid = obj.attr("id");
        data.sign=GetSign(data.act);        
		mui.getJSON(crm_domain, data, function (json) {
            if (json.state) {
                Receive_ContactInfo();
            } else {
            }
        });
		CloseWindow();
	});
};


